package com.test.hanlp.participle.controller;

import com.test.hanlp.participle.po.CustomTermPo;
import com.test.hanlp.participle.service.impl.WordSegmentationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Package: com.test.hanlp.participle.controller
 * @ClassName WordSegmentationController
 * @Description: 词根api
 * @Author: ky.zhang
 * @Date 2024/7/16 18:41
 * @Version v1.0
 **/
@RestController
@RequestMapping("/api")
@Api(value = "分词服务", tags = "分词服务", description = "分词服务 API")
public class WordSegmentationController {

    @Autowired
    private WordSegmentationService wordSegmentationService;

    @GetMapping("/segment")
    @ApiOperation(value = "分词", notes = "对输入文本进行分词")
    public Map<String, String> segment(@ApiParam("分词文本") String text) {
        return wordSegmentationService.segment(text);
    }

    @GetMapping("/segment1")
    @ApiOperation(value = "分词", notes = "对输入文本进行分词")
    public List<CustomTermPo> segment1(@ApiParam("分词文本") String text) {
        return wordSegmentationService.segment1(text);
    }

    @PostMapping("/addCustomDictionary")
    @ApiOperation(value = "添加自定义词典", notes = "向自定义词典添加词汇")
    public boolean addHanlpCustomDictionary(@ApiParam("自定义词汇") @RequestParam String word) {
        return wordSegmentationService.addHanlpCustomDictionary(word);
    }

    @DeleteMapping("/removeCustomDictionary/{word}")
    @ApiOperation(value = "移除自定义词典", notes = "从自定义词典移除词汇")
    public boolean removeHanlpCustomDictionary(@ApiParam("自定义词汇") @PathVariable String word) {
        return wordSegmentationService.removeHanlpCustomDictionary(word);
    }

    @GetMapping("/queryDicts")
    @ApiOperation(value = "查询自定义词典", notes = "查询自定义词典")
    public String queryDicts() {
        return wordSegmentationService.queryCustomDictionary();
    }

    @GetMapping("/queryTerms")
    @ApiOperation(value = "查询自定义术语", notes = "查询自定义术语中的词汇")
    public String queryTerms() {
        return wordSegmentationService.queryTerms();
    }

    @PostMapping("/addTerm")
    @ApiOperation(value = "添加自定义术语", notes = "向自定义术语添加词汇")
    public boolean addTerm(@ApiParam("自定义术语") @RequestParam String key,@ApiParam("自定义术语转换值") @RequestParam String replacement,@ApiParam("自定义术语转换值缩写") @RequestParam String abbreviation) {
        return wordSegmentationService.addTerm(key, replacement,abbreviation);
    }

    @DeleteMapping("/removeTerm/{key}")
    @ApiOperation(value = "移除自定义术语", notes = "向自定义术语移除词汇")
    public boolean removeTerm(@ApiParam("自定义术语") @PathVariable String key) {
        return wordSegmentationService.removeTerm(key);
    }
}

